package org.yuyao.security.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.yuyao.security.annotation.AccessLog;

import java.lang.reflect.Method;

@Aspect
@Component
public class LogAspect {

    private  final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Pointcut("@annotation(org.yuyao.security.annotation.AccessLog)")
    public void pointCut(){}

    @Around("pointCut()")
    public Object loginRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature ms= (MethodSignature) joinPoint.getSignature();
        Method method=ms.getMethod();
        AccessLog accessLog= method.getAnnotation(AccessLog.class);
       logger.info("用户{}访问了方法:{}->{}","zmx",method.getName(),accessLog.value());
       Object result=joinPoint.proceed();
        return result;
    }
}
